package stud.aistar.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import stud.aistar.entity.Treatment;

import java.util.List;

/**
 * *
 *
 * @ClassName :wangyu
 * @Description
 * @Author
 * @Date2019/9/28 14:42
 * @Version V1.0
 */
public interface TreatmentMapper {

    //病历信息表所有信息
    @Select("select * from treatment where tre_status = 0 and doc_id = #{docId} ORDER BY create_time")
    List<Treatment> findAll(Integer dId);
    //查询单个病人通过名字模糊查询
    @Select("select * from treatment where pat_name = #{value}")
    Treatment findByName(String patName);
    //更新信息通过id
    @Update("update treatment set pat_name = #{t.patName},pat_age = #{t.patAge},pat_sex = #{t.patSex},doc_name = #{t.docName},con_name = #{t.conName},intro = #{t.intro},tre_status = #{t.treStatus},doc_id = #{t.docId} where id = #{tid}")
    void updById(@Param("t") Treatment treatment,@Param("tid") Integer id);
    //删除病历信息
    @Update("update treatment set tre_status = 1 where id = #{tid}")
    void delById(@Param("tid") Integer id);
    //插入病人信息
    @Insert("Insert into treatment(pat_name,pat_age,person_card,doc_name,con_name,doc_type,intro,tre_status,pat_sex,doc_id,pat_id,create_time) values(#{t.patName},#{t.patAge},#{t.personCard},#{t.docName},#{t.conName},#{t.docType},#{t.intro},#{t.treStatus},#{t.patSex},#{t.docId},#{t.patId},#{t.createTime})")
    void insName(@Param("t") Treatment treatment);
    //统计就诊后人数
    @Select("select count(id) from treatment")
    int FindTreatmentCount();

    @Select("select * from treatment where pat_id = #{patId}")
    Treatment findByPatId(Integer patId);

    @Select("select * from treatment where tre_status = 0 and doc_id = #{ids} and pat_name like concat('%',#{pName},'%')")
    List<Treatment> findByPatName(@Param("pName") String patName ,@Param("ids") Integer dId);
}
